# Maintainer: Andrew Sun <adsun701@gmail.com>

_realname=mono-basic
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=4.8
pkgrel=2
pkgdesc="Mono Visual Basic.NET compiler (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://www.mono-project.com/"
license=('spdx:LGPL')
depends=("${MINGW_PACKAGE_PREFIX}-mono")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc" "git")
source=(#"${_realname}-${pkgver}.tar.xz"::"https://download.mono-project.com/sources/${_realname}/${_realname}-${pkgver}.tar.bz2"
        "${_realname}-${pkgver}::git+https://github.com/mono/mono-basic.git#commit=e31cb702937a0adcc853250a0989c5f43565f9b8"
        "0001-mono-basic-4.6-fix-slash-vs-hyphen.patch")
sha256sums=('SKIP'
            '8406a7e478b62c2d24000b4da3398a5c946b09cda1d61637c520faad9b993ec6')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -Np1 -i "${srcdir}/0001-mono-basic-4.6-fix-slash-vs-hyphen.patch"
}

build() {
  [[ -d "${srcdir}"/build-${MSYSTEM} ]] && rm -rf "${srcdir}"/build-${MSYSTEM}
  cp -Rf "${srcdir}"/${_realname}-${pkgver} "${srcdir}"/build-${MSYSTEM}
  cd "${srcdir}"/build-${MSYSTEM}

  # get rid of that .wapi errors
  export MONO_SHARED_DIR="${srcdir}/build-${MSYSTEM}/build"

  CC=${CC} CSC='mcs' \
  ./configure \
    --prefix=${MINGW_PREFIX}

  make
}

package() {
  cd "${srcdir}"/build-${MSYSTEM}
  make DESTDIR="${pkgdir}" install

  sed -e "s|/sdkpath|-sdkpath|g" -i "${pkgdir}${MINGW_PREFIX}/bin/vbnc2"
}
